import React, { Component } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import { Card, Badge, Table, Divider } from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import styles from './AgentProfile.less';

@connect(({ profile, loading }) => ({
  profile,
  loading: loading.effects['profile/fetchAgent'],
}))
export default class AgentProfile extends Component {

  getQueryString(name) { 
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
    var r = this.props.location.search.substr(1).match(reg); 
    if (r != null) return unescape(r[2]); return null; 
  }

  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'profile/fetchAgent',
    });
  }
  

  render() {
    const { profile, loading } = this.props;
    const { agents } = profile;
    const goodsColumns = [
      {
        title: 'ID',
        dataIndex: 'id',
        key: 'id',
      },
      {
        title: 'Uuid',
        dataIndex: 'uuid',
        key: 'uuid',
      },
      {
        title: 'host_name',
        dataIndex: 'host_name',
        key: 'host_name',
      },
      {
        title: 'ip',
        dataIndex: 'ip',
        key: 'ip',
      },
      {
        title: 'click',
        dataIndex: 'click',
        key: 'click',
      },
      {
        title: 'desc',
        dataIndex: 'desc',
        key: 'desc',
      },
      {
        title: 'work_id',
        dataIndex: 'work_id',
        key: 'work_id',
      },
      {
        title: 'update_time',
        dataIndex: 'update_time',
        key: 'update_time',
        render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
      },
      {
        title: 'create_time',
        dataIndex: 'create_time',
        key: 'create_time',
        render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
      },
    ];
    return (
      <PageHeaderLayout title="机器列表页">
        <Card bordered={false}>
          <Table
            style={{ marginBottom: 24 }}
            pagination={false}
            loading={loading}
            dataSource={agents}
            columns={goodsColumns}
            rowKey="id"
          />
        </Card>
      </PageHeaderLayout>
    );
  }
}
